package com.ruix.app.util;

import android.text.TextUtils;
import android.util.Log;

import com.ruix.app.constant.ReleaseConstant;

/**
 * Created by hadexs on 2017/4/13.
 */

public class LogUitl {

    private static String TAG = "RuiX";

    public static void d(String tag, String message) {
        if (ReleaseConstant.ISDEBUG) {
            Log.d(tag, formatJson(message));
        }
    }

    public static void d(String message) {
        if (ReleaseConstant.ISDEBUG) {
            Log.d(TAG, formatJson(message));
        }
    }


    public static void i(String tag, String message) {
        if (ReleaseConstant.ISDEBUG) {
            Log.i(tag, formatJson(message));
        }

    }

    public static void i(String message) {
        if (ReleaseConstant.ISDEBUG) {
            Log.i(TAG, formatJson(message));
        }
    }


    public static void w(String tag, String message) {
        Log.w(tag, formatJson(message));
    }

    public static void w(String message) {
        Log.w(TAG, formatJson(message));
    }

    public static void e(String tag, String message) {
        if (ReleaseConstant.ISDEBUG) {
            Log.e(tag, formatJson(message));
        } else {
//            UserLog.e(tag, formatJson(message));
        }

    }

    public static void e(String message) {
        if (ReleaseConstant.ISDEBUG) {
//            Log.e(TAG, message);
            Log.e(TAG, formatJson(message));
        } else {
//            UserLog.e(tag, formatJson(message));
        }

    }

    public static int e(String tag, String msg, Throwable tr) {
        return Log.e(tag, msg, tr);
    }


    private static String formatJson(String jsonString) {
        if (!TextUtils.isEmpty(jsonString)) {
            StringBuffer buffer = new StringBuffer();
            char c;
            for (int i = 0; i < jsonString.length(); i++) {
                c = jsonString.charAt(i);
                buffer.append(c);
                if (c == '{' || c == ',' || c == '[') {
                    buffer.append("\n");
                }
            }
            return buffer.toString();
        } else {
            return "";
        }
    }

}
